package com.xzp;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 代码清单6-1 反射技术
 *
 * @author briarbear
 * @blog https://briarbear.github.io
 * @create 2018-07-20-13:06
 */
public class ReflectService {

    public void sayHello(String name){
        System.out.println("hello " + name);
    }


    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        //通过反射创建 ReflectService
        Object service = Class.forName(ReflectService.class.getName()).newInstance();
        //获取服务方法
        Method method = service.getClass().getMethod("sayHello",String.class);
        //反射调用方法
        method.invoke(service,"xiongzp08");
    }

}
